/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import java.awt.Color;
import java.awt.Graphics;
import java.io.Serializable;

/**
 *Car dynamically creates itself with respect to arguments
 * @author Pro
 */
public class Car implements Serializable {
// int x,y were kept with simple names as they are called many times a second by the display and when there are many cars........

    private int x, y, xOff, yOff, laneID, carsIndex, carType;

    private int newX;                                   //
    private int newY;                                   //       attributes  for when car changes lanes
    private int newLaneID;                         //
    private boolean isChanging;                 //

    private int carWidth, carLength = 0;
    private Color color;

    //coord in constructor is the postion of the lane constant co-ordinate
    /**
     *Constructor for Car with four arguments of type Integer
     * @param index carries in value of the car's index in car array list
     * @param coord is a variable that is set by the creation of the lane
     * @param flow determines the horizontal or vertical
     * @param type for creation of different cars
     */
    public Car(int index, int coord, int flow, int type) {

        carType = type;
        carsIndex = index;
        if (type == 0) {
            color = new Color(0xFF00FF);
            xOff = 4;
            yOff = 4;

        }

        if (type == 1) {
            color = new Color(0xFDD017);
            xOff = 2;
            yOff = 2;

        }
        if (type == 2) {
            color = new Color(0x0000FF);
            xOff = 1;
            yOff = 1;

        }

        if (flow == 0) {

            carLength += 20;
            carWidth += 10;
            x = -30;
            y = coord + 10;
            yOff *= 0;
        }

        if (flow == 1) {

            carLength += 10;
            carWidth += 20;
            x = coord + 10;
            y = 810;
            xOff *= 0;
            yOff *= -1;
        }

    }

    /**
     *
     * @return the index of car in the array list
     */
    public int getCarsIndex() {
        return carsIndex;
    }

    /**
     *
     * @param carsIndex for use in change of lanes implementation
     */
    public void setCarsIndex(int carsIndex) {
        this.carsIndex = carsIndex;
    }

    /**
     *
     * @return the X coordinate
     */
    public int getX() {
        return x;
    }

    /**
     *
     * @param x X-coordinate is set
     */
    public void setX(int x) {
        this.x = x;
    }

    /**
     *
     * @return the Y coordinate
     */
    public int getY() {
        // do addition of car type here taking the + 25 from where it is called
        // this ends up being same efficiencey

        return y;
    }

    /**
     *
     * @param Y-coordinate is set
     */
    public void setY(int y) {
        this.y = y;
    }

    /**
     *
     * @return the x movement of car
     */
    public int getxOff() {
        return xOff;
    }

    /**
     *
     * @return the y movement of car
     */
    public int getyOff() {
        return yOff;
    }

    /**
     *
     * @param g called by carsDisplay to paint object to screen
     */
    public void draw(Graphics g) {

        g.setColor(color);
        g.fillRect(x, y, carLength, carWidth);

    }

    /**
     * implements the car to move
     */
    public void move() {
        x += xOff;
        y += yOff;

    }
}
